(function (angular) {
    'use strict';

    angular.module('ytong.directives').directive('morrisBarchart', function(){

        var BAR = "Bar";
        var LINE = "Line";

        return {

            // required to make it work as an element
            restrict: 'E',
            template: '<div></div>',
            replace: true,
            // observe and manipulate the DOM
            link: function ($scope, element, attrs) {

                var chart = $scope[attrs.chart];
                var callbackFunction = $scope[attrs.callback];
                if(callbackFunction === undefined){
                    callbackFunction = function(){};
                }

                var data = chart.data,
                    xkey = chart.xkey,
                    ykeys = chart.ykeys,
                    labels = chart.labels,
                    callback = callbackFunction,
                    preUnits = attrs.preunits;

                switch(attrs.type){
                    case BAR:{
                        Morris.Bar({
                            element: element,
                            data: data,
                            xkey: xkey,
                            ykeys: ykeys,
                            labels: labels,

                            //Optoins
                            hideHover: true,
                            gridTextSize: 14
                        }).on('click', callback);
                        break;
                    };
                    case LINE:{
                            Morris.Line({
                                element: element,
                                data: data,
                                xkey: xkey,
                                ykeys: ykeys,
                                labels: labels,

                                //Optoins
                                hideHover: true,
                                gridTextSize: 14,
                                parseTime: false,
                                preUnits: preUnits
                            }).on('click', callback);
                            break;
;                    }
                };
            }
        };
    });

    }(angular));